package org.example.view.Frame;

import org.example.view.componet.ATMButton;
import org.example.view.componet.BackgroundScene;
import org.example.view.componet.ButtonTypeEnum;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * 密码修改页面
 */
public class ModifyAtm extends JPanel {

    /**
     * 背景
     */
    private BackgroundScene backgroundScene;

    /**
     * 清除按钮
     */
    private ATMButton clearButton;

    /**
     * 确定按钮
     */
    private ATMButton sureButton;

    /**
     * 退出按钮
     */
    private ATMButton offButton;

    /**
     * 操作框
     */
    private JLabel pane;

    /**
     * 旧密码提示
     */
    private JLabel oldPassword;

    /**
     * 新密码提示
     */
    private JLabel newPassword;

    /**
     * 旧密码输入
     */
    private JTextField oldPasswordInput;

    /**
     * 新密码输入
     */
    private JTextField newPasswordInput;

    public ModifyAtm(JPanel panel) {
        this.addContent(panel);
    }

    private void addContent(JPanel panel) {
        this.setLayout(null);

        /**
         * 退出按钮（跳转选择页面）
         */
        this.offButton = new ATMButton(ButtonTypeEnum.退出, 450, 650);
        this.offButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "choose");
            }
        });
        this.add(this.offButton);

        /**
         * 清除按钮（清除密码）
         */
        this.clearButton = new ATMButton(ButtonTypeEnum.清除, 20, 475);
        this.clearButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                oldPasswordInput.setText(null);
                newPasswordInput.setText(null);
            }
        });
        this.add(this.clearButton);

        /**
         * 确认按钮（提交密码）
         */
        this.sureButton = new ATMButton(ButtonTypeEnum.确定, 880, 475);
        this.sureButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });
        this.add(this.sureButton);

        /**
         * 旧密码提示
         */
        this.oldPassword = new JLabel();
        this.oldPassword.setText("请输入旧密码：");
        this.oldPassword.setFont(new Font("宋体", Font.ITALIC, 21));
        this.oldPassword.setForeground(Color.blue);
        this.oldPassword.setBounds(260, 290, 150, 25);
        this.add(this.oldPassword);

        /**
         * 旧密码输入
         */
        this.oldPasswordInput = new JTextField();
        this.oldPasswordInput.setBounds(425, 280, 200, 35);
        this.add(this.oldPasswordInput);

        /**
         * 新密码提示
         */
        this.newPassword = new JLabel();
        this.newPassword.setText("请输入新密码：");
        this.newPassword.setFont(new Font("宋体", Font.ITALIC, 21));
        this.newPassword.setForeground(Color.blue);
        this.newPassword.setBounds(260, 350, 150, 25);
        this.add(this.newPassword);

        /**
         * 新密码输入
         */
        this.newPasswordInput = new JTextField();
        this.newPasswordInput.setBounds(425, 345, 200, 35);
        this.add(this.newPasswordInput);

        /**
         * 操作框
         */
        this.pane = new JLabel(new ImageIcon("/Users/cengyunke/Desktop/atm1/ATMGUI/src/main/java/org/example/img/pane.jpg"));
        this.pane.setBounds(210, 250, 620, 200);
        this.add(this.pane);

        /**
         * 背景
         */
        this.backgroundScene = new BackgroundScene();
        this.add(this.backgroundScene);
    }
}
